package com.lablzh.gdxy.controller;

import com.lablzh.gdxy.common.ueditor.ActionEnter;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

@RestController
@RequestMapping("/sys/ueditor")
public class UeditorController {

    @CrossOrigin
    @RequestMapping(value = "/exec")
    @ResponseBody
    public void exec(HttpServletRequest request, HttpServletResponse response) throws IOException {

        response.setContentType("application/json");
        String exec = "";
        request.setCharacterEncoding("utf-8");
//        String rootPath="./resources";
        String filePath = new File(ResourceUtils.getURL("classpath:").getPath()).getParentFile().getParentFile().getParent();
        String  rootPath=filePath.substring(5);
        System.out.println("根路径："+rootPath);
        exec = new ActionEnter(request, rootPath).exec();
        PrintWriter writer = response.getWriter();
        writer.write(exec);
        writer.flush();
        writer.close();
    }

}


